{% extends "base.html" %}

{% block content %}
  <div class="king-page-box">
        <div class="king-container clearfix">
           
            <div class="panel panel-success mb0">
                <div class="panel-heading"> 题库管理 </div>
                <div class="panel-body">
                    <form class="form-vertical p15">
                        <div class="form-group">
                           <a href="{{ SITE_URL }}bk_test_systerm/test_tm" class="king-btn mr10  king-success" ><span>试题新增</span></a>	   
                           <a onclick="flash_tm()" class="king-btn mr10  king-default" ><span>试题刷新</span></a>	                                                             
                        </div>
                         <div style="height:310px; overflow: auto;" id="list_1526104329322" class="king-list3 m0">
                            <table class="table mb0 pr15 ranger-box">
                                <tbody></tbody>
                            </table>
                        </div>
                        <template id="ranger_nodata_tpl">
                            <tr>
                                <td colspan="3"> 没有数据 </td>
                            </tr>
                        </template>
                        <template id="ranger_tpl_title">
                            <tr>
                                <th style="width: 70px;">题目</th>
                                <th style="width: 15%;">答案A</th>
                                <th style="width: 15%;">答案B</th>
                                <th style="width: 15%;">答案C</th>
                                <th style="width: 15%;">答案D</th>
                                <th style="width: 15%;">正确答案</th>
                                <th style="width: 10%;">操作</th>
                            </tr>
                        </template>
                        <template id="ranger_tpl">
                            <tr>
                                <td style="width: 70px;">#ask_name#</td>
                                <td style="width: 15%;">#ans_A#</td>
                                <td style="width: 15%;">#ans_B#</td>
                                <td style="width: 15%;">#ans_C#</td>
                                <td style="width: 15%;">#ans_D#</td>
                                <td style="width: 15%;">#ans_sucess#</td>
                                <td style="width:50px;cursor:pointer;color:blue" onclick="delete_tm('#ask_name#')">删除</td>
                            </tr>
                        </template>
                        <!-- 设置面板End -->
                    </form>
                </div>
            </div>
            <div class="panel panel-success mb0">
                <div class="panel-heading"> 试卷管理 </div>
                <div class="panel-body">
                    <form class="form-vertical p15">
                        <div class="form-group">
                            {% comment %} <button type="button" class="king-btn mr10  king-success">试卷生成</button> {% endcomment %}
                            {% comment %} <button type="button" class="king-btn king-default ">试卷销毁</button> {% endcomment %}
                        </div>
                    </form>
                </div>
            </div>
            <div class="panel panel-success mb0">
                <div class="panel-heading"> 考试管理 </div>
                <div class="panel-body">
                    <form class="form-vertical p15">
                        <div class="form-group">
                            {% comment %} <button type="button" class="king-btn mr10  king-success">考试成绩查询</button> {% endcomment %}
                            {% comment %} <button type="button" class="king-btn king-default ">模拟考试</button> {% endcomment %}
                        </div>
                    </form>
                </div>
            </div>
            <form class="form-horizontal">
                <section>
                    <div class="form-group clearfix">
                        <div class="col-sm-offset-3 col-sm-9">
                            <div class="bk-horizontal-line"></div>
                        </div>
                    </div>
                </section>
                <div class="panel panel-success mb0">
                    <div class="panel-heading"> 考生考试 </div>
                    <div class="panel-body">
                        <div class="form-group">
                            {% comment %} <button type="button" class="king-btn mr10  king-success">考试开始</button>                             {% endcomment %}
                        </div>
                    </div>
                </div>
            </form>

             <div class="progress progress-striped active">
                {% comment %} <div style="width: 55%" class="progress-bar progress-bar-danger "></div> {% endcomment %}
                <div id="test" class="progress-bar progress-bar-danger" role="progressbar" style="width: 10%;">刷新中:{{length}}%</div>
            </div>            
        </div>
    </div>  
	
{% endblock %}

 {% block extra_block %}
<script>
    $(function(){ 
            
            init_tm_info({
                    url: '{{ SITE_URL }}bk_test_systerm/records/',
                    dataType: 'json',
                    container: '#list_1526104329322 .ranger-box tbody'
                });
        });
    function renderTpl(str, cfg) {
        var re = /(#(.+?)#)/g;

        return str.replace(re, function() {
            var val = cfg[arguments[2]]+'';
            if(typeof val == 'undefined') {
                val = '';
            }
            return val;
        });
    }
    function init_tm_info(conf){
    // 异步请求后台数据
        $.ajax({
            url: conf.url,
            type: 'GET',
            dataType: conf.dataType,
            success: function(res){
                //获取数据成功
                if (res.code == 0){
                    var _html = ' ';
                    var list = res.data;
                    
                    var tpl = $('#ranger_tpl').html();
                    if (list.length == 0){
                        _html = $('#ranger_nodata_tpl').html();
                    }else{
                        _html+=$('#ranger_tpl_title').html();
                        for (var i=0,len=list.length; i < len; i++){
                            var item = list[i];
                            _html += renderTpl(tpl, item)
                        }
                    }
                    $(conf.container).html(_html);
                }
            }
        });
    }
    
    function delete_tm(obj){
         $.post('{{ SITE_URL }}bk_test_systerm/delete_tm/', {'ask_name': obj}, function(data){
             init_tm_info({
                    url: '{{ SITE_URL }}bk_test_systerm/records/',
                    dataType: 'json',
                    container: '#list_1526104329322 .ranger-box tbody'
                });
        }, 'json')
        return
    }
    function flash_tm(){
         init_tm_info({
                    url: '{{ SITE_URL }}bk_test_systerm/records/',
                    dataType: 'json',
                    container: '#list_1526104329322 .ranger-box tbody'
                });
    }
    </script>
{% endblock %}